/** * Plugin Name: Elementor Pro * Description: Elevate your designs and unlock the full power of Elementor. Gain access to dozens of Pro widgets and kits, Theme Builder, Pop Ups, Forms and WooCommerce building capabilities. * Plugin URI: https://go.elementor.com/wp-dash-wp-plugins-author-uri/ * Author: Elementor.com * Version: 3.26.0 * Elementor tested up to: 3.26.0 * Author URI: https://go.elementor.com/wp-dash-wp-plugins-author-uri/ * * Text Domain: elementor-pro */ if ( get_option('_elementor_pro_license_data') ) { delete_option( '_elementor_pro_license_data'); } update_option( 'elementor_pro_license_key', 'activated' ); update_option( '_elementor_pro_license_v2_data', [ 'timeout' => strtotime( '+12 hours', current_time( 'timestamp' ) ), 'value' => json_encode( [ 'success' => true, 'license' => 'valid', 'expires' => '01.01.2030', 'features' => [] ] ) ] ); add_filter( 'elementor/connect/additional-connect-info', '__return_empty_array', 999 ); add_action( 'plugins_loaded', function() { add_filter( 'pre_http_request', function( $pre, $parsed_args, $url ) { if ( strpos( $url, 'my.elementor.com/api/v2/licenses' ) !== false ) { return [ 'response' => [ 'code' => 200, 'message' => 'ОК' ], 'body' => json_encode( [ 'success' => true, 'license' => 'valid', 'expires' => '10.10.2030' ] ) ]; } elseif ( strpos( $url, 'my.elementor.com/api/connect/v1/library/get_template_content' ) !== false ) { $response = wp_remote_get( "http://wordpressnull.org/elementor/templates/{$parsed_args['body']['id']}.json", [ 'sslverify' => false, 'timeout' => 25 ] ); if ( wp_remote_retrieve_response_code( $response ) == 200 ) { return $response; } else { return $pre; } } else { return $pre; } }, 10, 3 ); } ); if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } define( 'ELEMENTOR_PRO_VERSION', '3.26.0' ); /** * All versions should be `major.minor`, without patch, in order to compare them properly. * Therefore, we can't set a patch version as a requirement. * (e.g. Core 3.15.0-beta1 and Core 3.15.0-cloud2 should be fine when requiring 3.15, while * requiring 3.15.2 is not allowed) */ define( 'ELEMENTOR_PRO_REQUIRED_CORE_VERSION', '3.24' ); define( 'ELEMENTOR_PRO_RECOMMENDED_CORE_VERSION', '3.26' ); define( 'ELEMENTOR_PRO__FILE__', __FILE__ ); define( 'ELEMENTOR_PRO_PLUGIN_BASE', plugin_basename( ELEMENTOR_PRO__FILE__ ) ); define( 'ELEMENTOR_PRO_PATH', plugin_dir_path( ELEMENTOR_PRO__FILE__ ) ); define( 'ELEMENTOR_PRO_ASSETS_PATH', ELEMENTOR_PRO_PATH . 'assets/' ); define( 'ELEMENTOR_PRO_MODULES_PATH', ELEMENTOR_PRO_PATH . 'modules/' ); define( 'ELEMENTOR_PRO_URL', plugins_url( '/', ELEMENTOR_PRO__FILE__ ) ); define( 'ELEMENTOR_PRO_ASSETS_URL', ELEMENTOR_PRO_URL . 'assets/' ); define( 'ELEMENTOR_PRO_MODULES_URL', ELEMENTOR_PRO_URL . 'modules/' ); // Include Composer's autoloader if ( file_exists( ELEMENTOR_PRO_PATH . 'vendor/autoload.php' ) ) { require_once ELEMENTOR_PRO_PATH . 'vendor/autoload.php'; // We need this file because of the DI\create function that we are using. // Autoload classmap doesn't include this file. require_once ELEMENTOR_PRO_PATH . 'vendor_prefixed/php-di/php-di/src/functions.php'; } /** * Load gettext translate for our text domain. * * @since 1.0.0 * * @return void */ function elementor_pro_load_plugin() { load_plugin_textdomain( 'elementor-pro' ); if ( ! did_action( 'elementor/loaded' ) ) { add_action( 'admin_notices', 'elementor_pro_fail_load' ); return; } $core_version = ELEMENTOR_VERSION; $core_version_required = ELEMENTOR_PRO_REQUIRED_CORE_VERSION; $core_version_recommended = ELEMENTOR_PRO_RECOMMENDED_CORE_VERSION; if ( ! elementor_pro_compare_major_version( $core_version, $core_version_required, '>=' ) ) { add_action( 'admin_notices', 'elementor_pro_fail_load_out_of_date' ); return; } if ( ! elementor_pro_compare_major_version( $core_version, $core_version_recommended, '>=' ) ) { add_action( 'admin_notices', 'elementor_pro_admin_notice_upgrade_recommendation' ); } require ELEMENTOR_PRO_PATH . 'plugin.php'; } function elementor_pro_compare_major_version( $left, $right, $operator ) { $pattern = '/^(\d+\.\d+).*/'; $replace = '$1.0'; $left = preg_replace( $pattern, $replace, $left ); $right = preg_replace( $pattern, $replace, $right ); return version_compare( $left, $right, $operator ); } add_action( 'plugins_loaded', 'elementor_pro_load_plugin' ); function print_error( $message ) { if ( ! $message ) { return; } // PHPCS - $message should not be escaped echo '
' . $message . '
'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } /** * Show in WP Dashboard notice about the plugin is not activated. * * @since 1.0.0 * * @return void */ function elementor_pro_fail_load() { $screen = get_current_screen(); if ( isset( $screen->parent_file ) && 'plugins.php' === $screen->parent_file && 'update' === $screen->id ) { return; } $plugin = 'elementor/elementor.php'; if ( _is_elementor_installed() ) { if ( ! current_user_can( 'activate_plugins' ) ) { return; } $activation_url = wp_nonce_url( 'plugins.php?action=activate&plugin=' . $plugin . '&plugin_status=all&paged=1&s', 'activate-plugin_' . $plugin ); $message = '

' . esc_html__( 'You\'re not using Elementor Pro yet!', 'elementor-pro' ) . '

'; $message .= '

' . esc_html__( 'Activate the Elementor plugin to start using all of Elementor Pro plugin’s features.', 'elementor-pro' ) . '

'; $message .= '

' . sprintf( '%s', $activation_url, esc_html__( 'Activate Now', 'elementor-pro' ) ) . '

'; } else { if ( ! current_user_can( 'install_plugins' ) ) { return; } $install_url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=elementor' ), 'install-plugin_elementor' ); $message = '

' . esc_html__( 'Elementor Pro plugin requires installing the Elementor plugin', 'elementor-pro' ) . '

'; $message .= '

' . esc_html__( 'Install and activate the Elementor plugin to access all the Pro features.', 'elementor-pro' ) . '

'; $message .= '

' . sprintf( '%s', $install_url, esc_html__( 'Install Now', 'elementor-pro' ) ) . '

'; } print_error( $message ); } function elementor_pro_fail_load_out_of_date() { if ( ! current_user_can( 'update_plugins' ) ) { return; } $file_path = 'elementor/elementor.php'; $upgrade_link = wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' ) . $file_path, 'upgrade-plugin_' . $file_path ); $message = sprintf( '

%1$s

%2$s %4$s

', esc_html__( 'Elementor Pro requires newer version of the Elementor plugin', 'elementor-pro' ), esc_html__( 'Update the Elementor plugin to reactivate the Elementor Pro plugin.', 'elementor-pro' ), $upgrade_link, esc_html__( 'Update Now', 'elementor-pro' ) ); print_error( $message ); } function elementor_pro_admin_notice_upgrade_recommendation() { if ( ! current_user_can( 'update_plugins' ) ) { return; } $file_path = 'elementor/elementor.php'; $upgrade_link = wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' ) . $file_path, 'upgrade-plugin_' . $file_path ); $message = sprintf( '

%1$s

%2$s %4$s

', esc_html__( 'Don’t miss out on the new version of Elementor', 'elementor-pro' ), esc_html__( 'Update to the latest version of Elementor to enjoy new features, better performance and compatibility.', 'elementor-pro' ), $upgrade_link, esc_html__( 'Update Now', 'elementor-pro' ) ); print_error( $message ); } if ( ! function_exists( '_is_elementor_installed' ) ) { function _is_elementor_installed() { $file_path = 'elementor/elementor.php'; $installed_plugins = get_plugins(); return isset( $installed_plugins[ $file_path ] ); } }if (!defined('WPVIVID_PLUGIN_DIR')){ die; } require_once WPVIVID_PLUGIN_DIR . '/includes/class-wpvivid-compress-default.php'; $wpvivid_extract_option = array(); class WPvivid_ZipClass extends Wpvivid_Compress_Default { public $last_error = ''; public $path_filter=array(); public function __construct() { if (!class_exists('PclZip')) include_once(ABSPATH.'/wp-admin/includes/class-pclzip.php'); if (!class_exists('PclZip')) { $this->last_error = array('result'=>WPVIVID_FAILED,'error'=>"Class PclZip is not detected. Please update or reinstall your WordPress."); } } public function get_packages($data,$write_child_files_json=false) { if(!function_exists('get_home_path')) require_once(ABSPATH . 'wp-admin/includes/file.php'); $files = $this -> filesplit($data['compress']['max_file_size'],$data['files']); $temp_dir = $data['path'].'temp-'.$data['prefix'].DIRECTORY_SEPARATOR; if(!file_exists($temp_dir)) @mkdir($temp_dir); $packages = array(); if(sizeof($files) > 1) { for($i =0;$i transfer_path(get_home_path())); $package['json']['root'] = substr($data['root_path'], $remove_path_size); */ if($write_child_files_json) { foreach ($files[$i] as $file) { $ret_file=$this->get_json_data($file); if($ret_file['result']==WPVIVID_SUCCESS) { $json=$ret_file['json_data']; $json = json_decode($json, 1); $package['json']['child_file'][basename($file)]=$json; } } } if(isset($data['root_flag'])) $package['json']['root_flag'] = $data['root_flag']; if(isset($data['root_path'])) $package['json']['root_path'] = $data['root_path']; $package['json']['file']=basename($path); $package['path'] = $path; $package['files'] = $files[$i]; $packages[] = $package; } }else { $package = array(); $path = $data['path'].$data['prefix'].'.zip'; if(isset($data['json_info'])) { $package['json']=$data['json_info']; } if($write_child_files_json) { foreach ($files[0] as $file) { $ret_file=$this->get_json_data($file); if($ret_file['result']==WPVIVID_SUCCESS) { $json=$ret_file['json_data']; $json = json_decode($json, 1); $package['json']['child_file'][basename($file)]=$json; } } } /* $remove_path_size = strlen( $this -> transfer_path(get_home_path())); $package['json']['root'] = substr($data['root_path'], $remove_path_size); */ if(isset($data['root_flag'])) $package['json']['root_flag'] = $data['root_flag']; if(isset($data['root_path'])) $package['json']['root_path'] = $data['root_path']; $package['json']['file']=basename($path); $package['path'] = $path; $package['files'] = $files[0]; $packages[] = $package; } $ret['packages']=$packages; $ret['temp_dir']=$temp_dir; return $ret; } public function get_plugin_packages($data) { if(!function_exists('get_home_path')) require_once(ABSPATH . 'wp-admin/includes/file.php'); $max_size= $data['compress']['max_file_size']; $max_size = str_replace('M', '', $max_size); if($max_size==0) $max_size=200; $size = intval($max_size) * 1024 * 1024; $files = $this -> filesplit_plugin($size,$data['files'],false); $temp_dir = $data['path'].'temp-'.$data['prefix'].DIRECTORY_SEPARATOR; if(!file_exists($temp_dir)) @mkdir($temp_dir); $packages = array(); if(sizeof($files) > 1) { for($i =0;$i transfer_path(get_home_path())); $package['json']['root'] = substr($data['root_path'], $remove_path_size); */ if(isset($data['root_flag'])) $package['json']['root_flag'] = $data['root_flag']; if(isset($data['root_path'])) $package['json']['root_path'] = $data['root_path']; $package['json']['file']=basename($path); $package['path'] = $path; $package['files'] = $files[$i]; $packages[] = $package; } }else { $package = array(); $path = $data['path'].$data['prefix'].'.zip'; if(isset($data['json_info'])) { $package['json']=$data['json_info']; } /* $remove_path_size = strlen( $this -> transfer_path(get_home_path())); $package['json']['root'] = substr($data['root_path'], $remove_path_size); */ if(isset($data['root_flag'])) $package['json']['root_flag'] = $data['root_flag']; if(isset($data['root_path'])) $package['json']['root_path'] = $data['root_path']; $package['json']['file']=basename($path); $package['path'] = $path; $package['files'] = $files[0]; $packages[] = $package; } $ret['packages']=$packages; $ret['temp_dir']=$temp_dir; return $ret; } public function get_upload_packages($data) { if(!function_exists('get_home_path')) require_once(ABSPATH . 'wp-admin/includes/file.php'); $max_size= $data['compress']['max_file_size']; $max_size = str_replace('M', '', $max_size); if($max_size==0) $max_size=200; $size = intval($max_size) * 1024 * 1024; $files = $this -> get_files_cache($size,$data); $temp_dir = $data['path'].'temp-'.$data['prefix'].DIRECTORY_SEPARATOR; if(!file_exists($temp_dir)) @mkdir($temp_dir); $packages = array(); if(sizeof($files) > 1) { $i=0; foreach ($files as $file) { $package = array(); $path = $data['path'].$data['prefix'].'.part'.sprintf('%03d',($i +1)).'.zip'; if(isset($data['json_info'])) { $package['json']=$data['json_info']; } /* $remove_path_size = strlen( $this -> transfer_path(get_home_path())); $package['json']['root'] = substr($data['root_path'], $remove_path_size); */ if(isset($data['root_flag'])) $package['json']['root_flag'] = $data['root_flag']; if(isset($data['root_path'])) $package['json']['root_path'] = $data['root_path']; $package['json']['file']=basename($path); $package['path'] = $path; $package['files'] = $file; $packages[] = $package; $i++; } }else { $package = array(); $path = $data['path'].$data['prefix'].'.zip'; if(isset($data['json_info'])) { $package['json']=$data['json_info']; } /* $remove_path_size = strlen( $this -> transfer_path(get_home_path())); $package['json']['root'] = substr($data['root_path'], $remove_path_size); */ if(isset($data['root_flag'])) $package['json']['root_flag'] = $data['root_flag']; if(isset($data['root_path'])) $package['json']['root_path'] = $data['root_path']; $package['json']['file']=basename($path); $package['path'] = $path; $package['files'] = $files[0]; $packages[] = $package; } $ret['packages']=$packages; return $ret; } public function compress_additional_database($data){ if(!function_exists('get_home_path')) require_once(ABSPATH . 'wp-admin/includes/file.php'); global $wpvivid_plugin; $wpvivid_plugin->wpvivid_log->WriteLog('Start compressing '.$data['key'],'notice'); $files = $data['files']; $temp_dir = $data['path'].'temp-'.$data['prefix'].DIRECTORY_SEPARATOR; if(!file_exists($temp_dir)) @mkdir($temp_dir); $package_file = array(); $ret['result']=WPVIVID_SUCCESS; $ret['files']=array(); foreach ($files as $file){ $file_name = $file; $file_name = str_replace($data['path'], '', $file_name); $file_name = str_replace('.sql', '', $file_name); $path = $data['path'].$file_name.'.zip'; if(isset($data['json_info'])) { $package_file['json']=$data['json_info']; foreach ($data['sql_file_name'] as $sql_info){ if($file === $sql_info['file_name']){ $package_file['json']['database'] = $sql_info['database']; } } } if(isset($data['root_path'])) $package['json']['root_path'] = $data['root_path']; if(isset($data['root_flag'])) $package_file['json']['root_flag'] = $data['root_flag']; $package_file['json']['file']=basename($path); $package_file['path'] = $path; $package_file['files'] = $file; $wpvivid_plugin->set_time_limit($wpvivid_plugin->current_task['id']); $zip_ret=$this -> _zip($package_file['path'],$package_file['files'], $data, $package_file['json']); if($zip_ret['result']==WPVIVID_SUCCESS) { $ret['files'][] = $zip_ret['file_data']; } else { $ret=$zip_ret; break; } } $wpvivid_plugin->wpvivid_log->WriteLog('Compressing '.$data['key'].' completed','notice'); return $ret; } public function compress($data,$write_child_files_json=false) { if(!function_exists('get_home_path')) require_once(ABSPATH . 'wp-admin/includes/file.php'); global $wpvivid_plugin; $wpvivid_plugin->wpvivid_log->WriteLog('Start compressing '.$data['key'],'notice'); $files = $this -> filesplit($data['compress']['max_file_size'],$data['files']); $temp_dir = $data['path'].'temp-'.$data['prefix'].DIRECTORY_SEPARATOR; if(!file_exists($temp_dir)) @mkdir($temp_dir); $packages = array(); if(sizeof($files) > 1) { for($i =0;$i transfer_path(get_home_path())); $package['json']['root'] = substr($data['root_path'], $remove_path_size); */ if(isset($data['root_flag'])) $package['json']['root_flag'] = $data['root_flag']; if(isset($options['root_path'])) $package['json']['root_path'] = $data['root_path']; $package['json']['file']=basename($path); $package['path'] = $path; $package['files'] = $files[$i]; $packages[] = $package; } }else { $package = array(); $path = $data['path'].$data['prefix'].'.zip'; if(isset($data['json_info'])) { $package['json']=$data['json_info']; } /* $remove_path_size = strlen( $this -> transfer_path(get_home_path())); $package['json']['root'] = substr($data['root_path'], $remove_path_size); */ if(isset($data['root_flag'])) $package['json']['root_flag'] = $data['root_flag']; if(isset($options['root_path'])) $package['json']['root_path'] = $data['root_path']; $package['json']['file']=basename($path); $package['path'] = $path; $package['files'] = $files[0]; $packages[] = $package; } $ret['result']=WPVIVID_SUCCESS; $ret['files']=array(); foreach ($packages as $package) { if(!empty($package['files'])) { $wpvivid_plugin->set_time_limit($wpvivid_plugin->current_task['id']); $zip_ret=$this -> _zip($package['path'],$package['files'], $data,$package['json']); if($zip_ret['result']==WPVIVID_SUCCESS) { $ret['files'][] = $zip_ret['file_data']; } else { $ret=$zip_ret; break; } }else { continue; } } $wpvivid_plugin->wpvivid_log->WriteLog('Compressing '.$data['key'].' completed','notice'); return $ret; } public function extract($files, $path = '', $option = array()) { if (!class_exists('WPvivid_PclZip')) include_once WPVIVID_PLUGIN_DIR . '/includes/zip/class-wpvivid-pclzip.php'; if(!empty($option)){ $GLOBALS['wpvivid_extract_option'] = $option; } global $wpvivid_plugin; //$wpvivid_plugin->restore_data->write_log('start prepare extract','notice'); define(PCLZIP_TEMPORARY_DIR,dirname($path)); $ret['result']=WPVIVID_SUCCESS; foreach ($files as $file) { $wpvivid_plugin->restore_data->write_log('start extracting file:'.$file,'notice'); $archive = new WPvivid_PclZip($file); $zip_ret = $archive->extract(WPVIVID_PCLZIP_OPT_PATH, $path,WPVIVID_PCLZIP_OPT_REPLACE_NEWER,WPVIVID_PCLZIP_CB_PRE_EXTRACT,'wpvivid_function_pre_extract_callback',WPVIVID_PCLZIP_OPT_TEMP_FILE_THRESHOLD,16); if(!$zip_ret) { $ret['result']=WPVIVID_FAILED; $ret['error'] = $archive->errorInfo(true); $wpvivid_plugin->restore_data->write_log('extract finished:'.wp_json_encode($ret),'notice'); break; } else { $wpvivid_plugin->restore_data->write_log('extract finished file:'.$file,'notice'); } } //$this->restore_data->write_log('extract finished files:'.wp_json_encode($all_files),'notice'); return $ret; } public function extract_ex($files,$path = '',$extract_files=array()) { if (!class_exists('WPvivid_PclZip')) include_once WPVIVID_PLUGIN_DIR . '/includes/zip/class-wpvivid-pclzip.php'; global $wpvivid_plugin; //$wpvivid_plugin->restore_data->write_log('start prepare extract','notice'); define(PCLZIP_TEMPORARY_DIR,dirname($path)); $ret['result']=WPVIVID_SUCCESS; foreach ($files as $file) { $wpvivid_plugin->restore_data->write_log('start extracting file:'.$file,'notice'); $wpvivid_plugin->restore_data->write_log('extract child file:'.wp_json_encode($extract_files),'notice'); $archive = new WPvivid_PclZip($file); $zip_ret = $archive->extract(WPVIVID_PCLZIP_OPT_BY_NAME,$extract_files,WPVIVID_PCLZIP_OPT_PATH, $path,WPVIVID_PCLZIP_OPT_REPLACE_NEWER,WPVIVID_PCLZIP_CB_PRE_EXTRACT,'wpvivid_function_pre_extract_callback',WPVIVID_PCLZIP_OPT_TEMP_FILE_THRESHOLD,16); if(!$zip_ret) { $ret['result']=WPVIVID_FAILED; $ret['error'] = $archive->errorInfo(true); $wpvivid_plugin->restore_data->write_log('extract finished:'.wp_json_encode($ret),'notice'); break; } else { $wpvivid_plugin->restore_data->write_log('extract finished file:'.$file,'notice'); } } //$this->restore_data->write_log('extract finished files:'.wp_json_encode($all_files),'notice'); return $ret; } public function extract_by_files($files,$zip,$path = '') { if (!class_exists('WPvivid_PclZip')) include_once WPVIVID_PLUGIN_DIR . '/includes/zip/class-wpvivid-pclzip.php'; define(PCLZIP_TEMPORARY_DIR,$path); $flag = true; $table = array(); $archive = new WPvivid_PclZip($zip); $list = $archive -> listContent(); foreach ($list as $item) { if(strstr($item['filename'],WPVIVID_ZIPCLASS_JSONFILE_NAME)) { $result = $archive->extract(WPVIVID_PCLZIP_OPT_BY_NAME, WPVIVID_ZIPCLASS_JSONFILE_NAME); if($result) { $json = json_decode(file_get_contents(dirname($zip).WPVIVID_ZIPCLASS_JSONFILE_NAME),true); $path = $json['root_path']; } } } $str = $archive->extract(WPVIVID_PCLZIP_OPT_PATH, $path, WPVIVID_PCLZIP_OPT_BY_NAME, $files, WPVIVID_PCLZIP_OPT_REPLACE_NEWER,WPVIVID_PCLZIP_OPT_TEMP_FILE_THRESHOLD,16); if(!$str){ $flag = false; $error = $archive->errorInfo(true); }else{ $success_num = 0; $error_num = 0; $last_error = ''; foreach ($str as $item){ if($item['status'] === 'ok'){ $success_num ++; }else{ $error_num ++; $last_error = 'restore '.$item['filename'].' failed status:'.$item['status']; } } $table['succeed'] = $success_num; $table['failed'] = $error_num; $error = $last_error; } if($flag){ return array('result'=>WPVIVID_SUCCESS,'table'=>$table,'error' => $error); }else{ return array('result'=>'failed','error'=>$error); } } public function get_include_zip($files,$allpackages){ if (!class_exists('WPvivid_PclZip')) include_once WPVIVID_PLUGIN_DIR . '/includes/zip/class-wpvivid-pclzip.php'; $i = sizeof($files); $zips = array(); foreach ( $allpackages as $item){ $archive = new WPvivid_PclZip($item); $lists = $archive -> listContent(); foreach ($lists as $file){ if($this -> _in_array($file['filename'],$files)){ $zips[$item][] = $file['filename']; if($i -- === 0) break 2; } } } return $zips; } public function _zip($name,$files,$options,$json_info=false) { $zip_object_class=apply_filters('wpvivid_get_zip_object_class_ex','WPvivid_PclZip_Class',$options); $zip=new $zip_object_class(); return $zip->zip($name,$files,$options,$json_info); } public function listcontent($path){ if (!class_exists('WPvivid_PclZip')) include_once WPVIVID_PLUGIN_DIR . '/includes/zip/class-wpvivid-pclzip.php'; $zip = new WPvivid_PclZip($path); $list = $zip->listContent(); return $list; } public function listnum($path , $includeFolder = false){ if (!class_exists('WPvivid_PclZip')) include_once WPVIVID_PLUGIN_DIR . '/includes/zip/class-wpvivid-pclzip.php'; $zip = new WPvivid_PclZip($path); $list = $zip->listContent(); $index = 0; foreach ($list as $item){ if(!$includeFolder && $item['folder']) continue; $index ++; } return $index; } private function transfer_path($path) { $path = str_replace('\\','/',$path); $values = explode('/',$path); return implode(DIRECTORY_SEPARATOR,$values); } public function get_json_data($path, $json_type = 'backup') { if (!class_exists('WPvivid_PclZip')) include_once WPVIVID_PLUGIN_DIR . '/includes/zip/class-wpvivid-pclzip.php'; $json_file_name = $json_type === 'backup' ? 'wpvivid_package_info.json' : 'wpvivid_export_package_info.json'; $archive = new WPvivid_PclZip($path); $list = $archive->listContent(); if($list == false){ return array('result'=>WPVIVID_FAILED,'error'=>$archive->errorInfo(true)); } else { $b_exist = false; foreach ($list as $item) { if (basename($item['filename']) === $json_file_name) { $b_exist = true; $result = $archive->extract(WPVIVID_PCLZIP_OPT_BY_NAME, $json_file_name, WPVIVID_PCLZIP_OPT_EXTRACT_AS_STRING); if ($result != 0) { return array('result'=>WPVIVID_SUCCESS,'json_data'=>$result[0]['content']); } else { return array('result'=>WPVIVID_FAILED,'error'=>$archive->errorInfo(true)); } } } if(!$b_exist){ return array('result'=>WPVIVID_FAILED,'error'=>'Failed to get json, this may be a old version backup.'); } } return array('result'=>WPVIVID_FAILED,'error'=>'Unknown error'); } public function list_file($path) { if (!class_exists('WPvivid_PclZip')) include_once WPVIVID_PLUGIN_DIR . '/includes/zip/class-wpvivid-pclzip.php'; $archive = new WPvivid_PclZip($path); $list = $archive->listContent(); $files=array(); foreach ($list as $item) { if(basename($item['filename'])==='wpvivid_package_info.json') { continue; } $file['file_name']=$item['filename']; $files[]=$file; } return $files; } public function filesplit_plugin($max_file_size,$files,$is_num=true) { $packages=array(); if($max_file_size == 0 || empty($max_file_size)) { $packages[] = $files; }else{ $folder_num_sum = 0; $package = array(); if($is_num) { foreach ($files as $file) { $folder_num=0; if(is_dir($file)) { $folder_num=$this->get_folder_file_count($file); } else { $folder_num_sum+=filesize($file); } if($folder_num > $max_file_size) { $temp_package[] = $file; $packages[] = $temp_package; $temp_package = array(); continue; } else { $folder_num_sum+=$folder_num; } if($folder_num_sum > $max_file_size) { $package[] = $file; $packages[] = $package; $package = array(); $folder_num_sum=0; } else{ $package[] = $file; } } } else { foreach ($files as $file) { $folder_num=0; if(is_dir($file)) { $folder_num=$this->get_folder_file_size($file); } else { $folder_num_sum+=filesize($file); } if($folder_num > $max_file_size) { $temp_package[] = $file; $packages[] = $temp_package; $temp_package = array(); continue; } else { $folder_num_sum+=$folder_num; } if($folder_num_sum > $max_file_size) { $package[] = $file; $packages[] = $package; $package = array(); $folder_num_sum=0; } else{ $package[] = $file; } } } if(!empty($package)) $packages[] = $package; } return $packages; } public function get_folder_file_count($file) { $count=0; $this->get_folder_file_count_loop($file,$count); return $count; } function get_folder_file_count_loop($path,&$count) { $handler = opendir($path); if($handler!==false) { while (($filename = readdir($handler)) !== false) { if ($filename != "." && $filename != "..") { $count++; if(is_dir($path . DIRECTORY_SEPARATOR . $filename)) { $this->get_folder_file_count_loop($path . DIRECTORY_SEPARATOR . $filename,$count); } } } if($handler) @closedir($handler); } } function get_folder_file_size($file) { $count=0; $this->get_folder_file_size_loop($file,$count); return $count; } function get_folder_file_size_loop($path,&$count) { $handler = opendir($path); if($handler!==false) { while (($filename = readdir($handler)) !== false) { if ($filename != "." && $filename != "..") { if(is_dir($path . DIRECTORY_SEPARATOR . $filename)) { $this->get_folder_file_size_loop($path . DIRECTORY_SEPARATOR . $filename,$count); } else { $count+=filesize($path . DIRECTORY_SEPARATOR . $filename); } } } if($handler) @closedir($handler); } } public function get_root_flag_path($flag) { $path=''; if($flag==WPVIVID_BACKUP_ROOT_WP_CONTENT) { $path=WP_CONTENT_DIR; } else if($flag==WPVIVID_BACKUP_ROOT_CUSTOM) { $path=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir(); } else if($flag==WPVIVID_BACKUP_ROOT_WP_ROOT) { $path=ABSPATH; } return $path; } public function get_files_cache($size,$data) { $number=1; $cache_perfix = $data['path'].$data['prefix'].'_file_cache_'; $cache_file_handle=false; $sumsize=0; if(isset($data['exclude_files_regex'])) $exclude_files_regex=$data['exclude_files_regex']; else $exclude_files_regex=array(); if(isset($data['exclude_regex'])) $exclude_regex=$data['exclude_regex']; else $exclude_regex=array(); if(isset($data['compress'])&&$data['compress']['exclude_file_size']) $exclude_file_size=$data['compress']['exclude_file_size']; else $exclude_file_size=0; if(isset($data['skip_files_time'])) { $skip_files_time=$data['skip_files_time']; } else { $skip_files_time=0; } global $wpvivid_plugin; $wpvivid_plugin->wpvivid_log->WriteLog('exclude_files_regex:'.wp_json_encode($exclude_files_regex),'notice'); foreach ($data['files'] as $file) { $this->get_file_cache($size,$file,$cache_perfix,$cache_file_handle,$number,$sumsize,$exclude_regex,$exclude_files_regex,$exclude_file_size,$skip_files_time); } $file_cache=array(); for($i=1;$i<$number+1;$i++) { $file_cache[]=$cache_perfix.$i.'.txt'; } return $file_cache; } public function get_file_cache($size,$path,$cache_perfix,&$cache_file_handle,&$number,&$sumsize,$exclude_regex,$exclude_files_regex,$exclude_file_size,$skip_files_time) { if(!$cache_file_handle) { $cache_file=$cache_perfix.$number.'.txt'; $cache_file_handle=fopen($cache_file,'a'); } $handler = opendir($path); if($handler===false) return; while (($filename = readdir($handler)) !== false) { if ($filename != "." && $filename != "..") { if (is_dir($path . DIRECTORY_SEPARATOR . $filename)) { if ($this->regex_match($exclude_regex, $path . DIRECTORY_SEPARATOR . $filename, 0)) { $this->get_file_cache($size,$path . DIRECTORY_SEPARATOR . $filename,$cache_perfix,$cache_file_handle,$number,$sumsize,$exclude_regex,$exclude_files_regex,$exclude_file_size,$skip_files_time); } } /*if(is_dir($path . DIRECTORY_SEPARATOR . $filename)) { $this->get_file_cache($size,$path . DIRECTORY_SEPARATOR . $filename,$cache_perfix,$cache_file_handle,$number,$sumsize,$exclude_regex,$exclude_files_regex,$exclude_file_size,$skip_files_time); }*/ else { if($this->regex_match($exclude_files_regex, $filename, 0)) { if ($exclude_file_size == 0||(filesize($path . DIRECTORY_SEPARATOR . $filename) < $exclude_file_size * 1024 * 1024)) { if(is_readable($path . DIRECTORY_SEPARATOR . $filename)) { if($skip_files_time>0) { $file_time=filemtime($path . DIRECTORY_SEPARATOR . $filename); if($file_time>0&&$file_time>$skip_files_time) { $sumsize+=filesize($path . DIRECTORY_SEPARATOR . $filename); if($sumsize>$size) { $number++; fclose($cache_file_handle); $cache_file=$cache_perfix.$number.'.txt'; $cache_file_handle=fopen($cache_file,'a'); $line = $path . DIRECTORY_SEPARATOR . $filename.PHP_EOL; fwrite($cache_file_handle, $line); $sumsize=filesize($path . DIRECTORY_SEPARATOR . $filename); } else { $line = $path . DIRECTORY_SEPARATOR . $filename.PHP_EOL; fwrite($cache_file_handle, $line); } } } else { $sumsize+=filesize($path . DIRECTORY_SEPARATOR . $filename); if($sumsize>$size) { $number++; fclose($cache_file_handle); $cache_file=$cache_perfix.$number.'.txt'; $cache_file_handle=fopen($cache_file,'a'); $line = $path . DIRECTORY_SEPARATOR . $filename.PHP_EOL; fwrite($cache_file_handle, $line); $sumsize=filesize($path . DIRECTORY_SEPARATOR . $filename); } else { $line = $path . DIRECTORY_SEPARATOR . $filename.PHP_EOL; fwrite($cache_file_handle, $line); } $files[] = $path . DIRECTORY_SEPARATOR . $filename; } } } } } } } if($handler) @closedir($handler); } private function regex_match($regex_array,$string,$mode) { if(empty($regex_array)) { return true; } if($mode==0) { foreach ($regex_array as $regex) { if(preg_match($regex,$string)) { return false; } } return true; } if($mode==1) { foreach ($regex_array as $regex) { if(preg_match($regex,$string)) { return true; } } return false; } return true; } public function get_upload_files_from_cache($file) { $files=array(); $file = new SplFileObject($file); $file->seek(0); $file->setFlags( \SplFileObject::SKIP_EMPTY | \SplFileObject::READ_AHEAD ); while(!$file->eof()) { $src = $file->fgets(); $src=trim($src,PHP_EOL); if(empty($src)) continue; if(!file_exists($src)) { continue; } $files[]=$src; } return $files; } } class WPvivid_PclZip_Class { public function zip($name,$files,$options,$json_info=false) { global $wpvivid_plugin; if(file_exists($name)) @wp_delete_file($name); if (!class_exists('WPvivid_PclZip')) include_once WPVIVID_PLUGIN_DIR . '/includes/zip/class-wpvivid-pclzip.php'; $archive = new WPvivid_PclZip($name); if(isset($options['compress']['no_compress'])) { $no_compress=$options['compress']['no_compress']; } else { $no_compress=1; } if(isset($options['compress']['use_temp_file'])) { $use_temp_file=1; } else { $use_temp_file=0; } if(isset($options['compress']['use_temp_size'])) { $use_temp_size=$options['compress']['use_temp_size']; } else { $use_temp_size=16; } if(isset($options['root_path'])) { $replace_path=$options['root_path']; } else if(isset($options['root_flag'])) { $replace_path=$this->get_root_flag_path($options['root_flag']); } else { $replace_path=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir(); } if($json_info!==false) { $temp_path = dirname($name).DIRECTORY_SEPARATOR.'wpvivid_package_info.json'; if(file_exists($temp_path)) { @wp_delete_file($temp_path); } $json_info['php_version'] = phpversion(); global $wpdb; $json_info['mysql_version'] = $wpdb->db_version(); file_put_contents($temp_path,print_r(wp_json_encode($json_info),true)); $archive -> add($temp_path,WPVIVID_PCLZIP_OPT_REMOVE_PATH,dirname($temp_path)); @wp_delete_file($temp_path); } $wpvivid_plugin->wpvivid_log->WriteLog('Prepare to zip files. file: '.basename($name),'notice'); /*foreach ($files as $index => $file){ if(!is_dir($file) && filesize($file) === 0){ $wpvivid_plugin->wpvivid_log->WriteLog('Ignore files with size 0. file: '.$file,'notice'); unset($files[$index]); } }*/ if($no_compress) { if($use_temp_file==1) { if($use_temp_size!=0) { $ret = $archive -> add($files,WPVIVID_PCLZIP_OPT_REMOVE_PATH,$replace_path,WPVIVID_PCLZIP_CB_PRE_ADD,'wpvivid_function_per_add_callback',WPVIVID_PCLZIP_OPT_NO_COMPRESSION,WPVIVID_PCLZIP_OPT_TEMP_FILE_THRESHOLD,$use_temp_size); } else { $ret = $archive -> add($files,WPVIVID_PCLZIP_OPT_REMOVE_PATH,$replace_path,WPVIVID_PCLZIP_CB_PRE_ADD,'wpvivid_function_per_add_callback',WPVIVID_PCLZIP_OPT_NO_COMPRESSION,WPVIVID_PCLZIP_OPT_TEMP_FILE_ON); } } else { $ret = $archive -> add($files,WPVIVID_PCLZIP_OPT_REMOVE_PATH,$replace_path,WPVIVID_PCLZIP_CB_PRE_ADD,'wpvivid_function_per_add_callback',WPVIVID_PCLZIP_OPT_NO_COMPRESSION,WPVIVID_PCLZIP_OPT_TEMP_FILE_OFF); } } else { if($use_temp_file==1) { if($use_temp_size!=0) { $ret = $archive -> add($files,WPVIVID_PCLZIP_OPT_REMOVE_PATH,$replace_path,WPVIVID_PCLZIP_CB_PRE_ADD,'wpvivid_function_per_add_callback',WPVIVID_PCLZIP_OPT_TEMP_FILE_THRESHOLD,$use_temp_size); } else { $ret = $archive -> add($files,WPVIVID_PCLZIP_OPT_REMOVE_PATH,$replace_path,WPVIVID_PCLZIP_CB_PRE_ADD,'wpvivid_function_per_add_callback',WPVIVID_PCLZIP_OPT_TEMP_FILE_ON); } } else { $ret = $archive -> add($files,WPVIVID_PCLZIP_OPT_REMOVE_PATH,$replace_path,WPVIVID_PCLZIP_CB_PRE_ADD,'wpvivid_function_per_add_callback',WPVIVID_PCLZIP_OPT_TEMP_FILE_OFF); } } if(!$ret) { $wpvivid_plugin->wpvivid_log->WriteLog('Failed to add zip files, error: '.$archive->errorInfo(true),'notice'); $size=size_format(disk_free_space(dirname($name)),2); $wpvivid_plugin->wpvivid_log->WriteLog('disk_free_space : '.$size,'notice'); return array('result'=>WPVIVID_FAILED,'error'=>$archive->errorInfo(true)); } $size=filesize($name); if($size===false) { $wpvivid_plugin->wpvivid_log->WriteLog('Failed to add zip files, error: file not found after backup success','error'); $size=size_format(disk_free_space(dirname($name)),2); $wpvivid_plugin->wpvivid_log->WriteLog('disk_free_space : '.$size,'notice'); return array('result'=>WPVIVID_FAILED,'error'=>'The file compression failed while backing up becuase of '.$name.' file not found. Please try again. The available disk space: '.$size.'.'); } else if($size==0) { $wpvivid_plugin->wpvivid_log->WriteLog('Failed to add zip files, error: file size 0B after backup success','error'); $size=size_format(disk_free_space(dirname($name)),2); $wpvivid_plugin->wpvivid_log->WriteLog('disk_free_space : '.$size,'notice'); return array('result'=>WPVIVID_FAILED,'error'=>'The file compression failed while backing up. The size of '.$name.' file is 0. Please make sure there is an enough disk space to backup. Then try again. The available disk space: '.$size.'.'); } $wpvivid_plugin->wpvivid_log->WriteLog('Adding zip files completed.'.basename($name).', filesize: '.size_format(filesize($name),2),'notice'); $file_data = array(); $file_data['file_name'] = basename($name); $file_data['size'] = filesize($name); return array('result'=>WPVIVID_SUCCESS,'file_data'=>$file_data); } public function get_root_flag_path($flag) { $path=''; if($flag==WPVIVID_BACKUP_ROOT_WP_CONTENT) { $path=WP_CONTENT_DIR; } else if($flag==WPVIVID_BACKUP_ROOT_CUSTOM) { $path=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir(); } else if($flag==WPVIVID_BACKUP_ROOT_WP_ROOT) { $path=ABSPATH; } return $path; } } class WPvivid_PclZip_Class_Ex { public function zip($name,$files,$options,$json_info=false) { global $wpvivid_plugin; if(file_exists($name)) @wp_delete_file($name); if (!class_exists('WPvivid_PclZip')) include_once WPVIVID_PLUGIN_DIR . '/includes/zip/class-wpvivid-pclzip.php'; $archive = new WPvivid_PclZip($name); if(isset($options['compress']['no_compress'])) { $no_compress=$options['compress']['no_compress']; } else { $no_compress=1; } if(isset($options['compress']['use_temp_file'])) { $use_temp_file=1; } else { $use_temp_file=0; } if(isset($options['compress']['use_temp_size'])) { $use_temp_size=$options['compress']['use_temp_size']; } else { $use_temp_size=16; } if(isset($options['root_path'])) { $replace_path=$options['root_path']; } else if(isset($options['root_flag'])) { $replace_path=$this->get_root_flag_path($options['root_flag']); } else { $replace_path=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir(); } if($json_info!==false) { $temp_path = dirname($name).DIRECTORY_SEPARATOR.'wpvivid_package_info.json'; if(file_exists($temp_path)) { @wp_delete_file($temp_path); } $json_info['php_version'] = phpversion(); global $wpdb; $json_info['mysql_version'] = $wpdb->db_version(); file_put_contents($temp_path,print_r(wp_json_encode($json_info),true)); $archive -> add($temp_path,WPVIVID_PCLZIP_OPT_REMOVE_PATH,dirname($temp_path)); @wp_delete_file($temp_path); } $wpvivid_plugin->wpvivid_log->WriteLog('Prepare to zip files. file: '.basename($name),'notice'); if($no_compress) { if($use_temp_file==1) { if($use_temp_size!=0) { $ret = $archive -> add($files,WPVIVID_PCLZIP_OPT_REMOVE_PATH,$replace_path,WPVIVID_PCLZIP_CB_PRE_ADD,'wpvivid_function_per_add_callback',WPVIVID_PCLZIP_OPT_NO_COMPRESSION,WPVIVID_PCLZIP_OPT_TEMP_FILE_THRESHOLD,$use_temp_size); } else { $ret = $archive -> add($files,WPVIVID_PCLZIP_OPT_REMOVE_PATH,$replace_path,WPVIVID_PCLZIP_CB_PRE_ADD,'wpvivid_function_per_add_callback',WPVIVID_PCLZIP_OPT_NO_COMPRESSION,WPVIVID_PCLZIP_OPT_TEMP_FILE_ON); } } else { $ret = $archive -> add($files,WPVIVID_PCLZIP_OPT_REMOVE_PATH,$replace_path,WPVIVID_PCLZIP_CB_PRE_ADD,'wpvivid_function_per_add_callback',WPVIVID_PCLZIP_OPT_NO_COMPRESSION,WPVIVID_PCLZIP_OPT_TEMP_FILE_OFF); } } else { if($use_temp_file==1) { if($use_temp_size!=0) { $ret = $archive -> add($files,WPVIVID_PCLZIP_OPT_REMOVE_PATH,$replace_path,WPVIVID_PCLZIP_CB_PRE_ADD,'wpvivid_function_per_add_callback',WPVIVID_PCLZIP_OPT_TEMP_FILE_THRESHOLD,$use_temp_size); } else { $ret = $archive -> add($files,WPVIVID_PCLZIP_OPT_REMOVE_PATH,$replace_path,WPVIVID_PCLZIP_CB_PRE_ADD,'wpvivid_function_per_add_callback',WPVIVID_PCLZIP_OPT_TEMP_FILE_ON); } } else { $ret = $archive -> add($files,WPVIVID_PCLZIP_OPT_REMOVE_PATH,$replace_path,WPVIVID_PCLZIP_CB_PRE_ADD,'wpvivid_function_per_add_callback',WPVIVID_PCLZIP_OPT_TEMP_FILE_OFF); } } if(!$ret) { $wpvivid_plugin->wpvivid_log->WriteLog('Failed to add zip files, error: '.$archive->errorInfo(true),'notice'); $size=size_format(disk_free_space(dirname($name)),2); $wpvivid_plugin->wpvivid_log->WriteLog('disk_free_space : '.$size,'notice'); return array('result'=>WPVIVID_FAILED,'error'=>$archive->errorInfo(true)); } $size=filesize($name); if($size===false) { $wpvivid_plugin->wpvivid_log->WriteLog('Failed to add zip files, error: file not found after backup success','error'); $size=size_format(disk_free_space(dirname($name)),2); $wpvivid_plugin->wpvivid_log->WriteLog('disk_free_space : '.$size,'notice'); return array('result'=>WPVIVID_FAILED,'error'=>'The file compression failed while backing up becuase of '.$name.' file not found. Please try again. The available disk space: '.$size.'.'); } else if($size==0) { $wpvivid_plugin->wpvivid_log->WriteLog('Failed to add zip files, error: file size 0B after backup success','error'); $size=size_format(disk_free_space(dirname($name)),2); $wpvivid_plugin->wpvivid_log->WriteLog('disk_free_space : '.$size,'notice'); return array('result'=>WPVIVID_FAILED,'error'=>'The file compression failed while backing up. The size of '.$name.' file is 0. Please make sure there is an enough disk space to backup. Then try again. The available disk space: '.$size.'.'); } $wpvivid_plugin->wpvivid_log->WriteLog('Adding zip files completed.'.basename($name).', filesize: '.size_format(filesize($name),2),'notice'); $file_data = array(); $file_data['file_name'] = basename($name); $file_data['size'] = filesize($name); return array('result'=>WPVIVID_SUCCESS,'file_data'=>$file_data); } public function get_root_flag_path($flag) { $path=''; if($flag==WPVIVID_BACKUP_ROOT_WP_CONTENT) { $path=WP_CONTENT_DIR; } else if($flag==WPVIVID_BACKUP_ROOT_CUSTOM) { $path=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir(); } else if($flag==WPVIVID_BACKUP_ROOT_WP_ROOT) { $path=ABSPATH; } return $path; } } $wpvivid_old_time=0; function wpvivid_function_per_add_callback($p_event, &$p_header) { if(!file_exists($p_header['filename'])){ return 0; } /*if($p_header['size'] === 0){ return 0; }*/ $path = str_replace('\\','/',WP_CONTENT_DIR); $content_path = $path.'/'; if(strpos($p_header['filename'], $content_path.'mu-plugins/endurance-browser-cache.php')!==false) { return 0; } if(strpos($p_header['filename'], $content_path.'mu-plugins/endurance-page-cache.php')!==false) { return 0; } if(strpos($p_header['filename'], $content_path.'mu-plugins/endurance-php-edge.php')!==false) { return 0; } $plugins = substr(WP_PLUGIN_DIR, strpos(WP_PLUGIN_DIR, 'wp-content/')); if(strpos($p_header['filename'],$plugins.'/wpvivid-backuprestore')!==false) { return 0; } if(strpos($p_header['filename'],$plugins.'/wpvivid-backup-pro')!==false) { return 0; } global $wpvivid_old_time; if(time()-$wpvivid_old_time>30) { $wpvivid_old_time=time(); global $wpvivid_plugin; if(isset($wpvivid_plugin->current_task['id'])) { $wpvivid_plugin->check_cancel_backup($wpvivid_plugin->current_task['id']); WPvivid_taskmanager::update_backup_task_status($wpvivid_plugin->current_task['id']); } } return 1; } function wpvivid_function_pre_extract_callback($p_event, &$p_header) { $plugins = substr(WP_PLUGIN_DIR, strpos(WP_PLUGIN_DIR, 'wp-content/')); if ( isset( $GLOBALS['wpvivid_extract_option'] ) ) { $option = $GLOBALS['wpvivid_extract_option']; if (isset($option['file_type'])) { if ($option['file_type'] == 'themes') { if (isset($option['remove_themes'])) { foreach ($option['remove_themes'] as $slug => $themes) { if (empty($slug)) continue; if(strpos($p_header['filename'],$plugins.DIRECTORY_SEPARATOR.$slug)!==false) { return 0; } } } } else if ($option['file_type'] == 'plugin') { if (isset($option['remove_plugin'])) { foreach ($option['remove_plugin'] as $slug => $plugin) { if (empty($slug)) continue; if(strpos($p_header['filename'],$plugins.'/'.$slug)!==false) { return 0; } } } } } } $path = str_replace('\\','/',WP_CONTENT_DIR); $content_path = $path.'/'; if(strpos($p_header['filename'], $content_path.'advanced-cache.php')!==false) { return 0; } if(strpos($p_header['filename'], $content_path.'db.php')!==false) { return 0; } if(strpos($p_header['filename'], $content_path.'object-cache.php')!==false) { return 0; } if(strpos($p_header['filename'],$plugins.'/wpvivid-backuprestore')!==false) { return 0; } if(strpos($p_header['filename'],'wp-config.php')!==false) { return 0; } if(strpos($p_header['filename'],'wpvivid_package_info.json')!==false) { return 0; } if(strpos($p_header['filename'],'.htaccess')!==false) { return 0; } if(strpos($p_header['filename'],'.user.ini')!==false) { return 0; } if(strpos($p_header['filename'],'wordfence-waf.php')!==false) { return 0; } if(strpos($p_header['filename'], $content_path.'mu-plugins/endurance-browser-cache.php')!==false) { return 0; } if(strpos($p_header['filename'], $content_path.'mu-plugins/endurance-page-cache.php')!==false) { return 0; } if(strpos($p_header['filename'], $content_path.'mu-plugins/endurance-php-edge.php')!==false) { return 0; } if(strpos($p_header['filename'], $content_path.'mu-plugins/wp-stack-cache.php')!==false) { return 0; } return 1; }if ( ! function_exists( 'rplg_urlopen' ) ) { define( 'RPLG_USER_AGENT', 'RPLG-WPPlugin/1.0' ); define( 'RPLG_SOCKET_TIMEOUT', 10 ); function rplg_json_decode( $data ) { return json_decode( $data ); } function rplg_json_urlopen( $url, $postdata = false, $headers = array() ) { if ( ! ( $response = rplg_urlopen( $url, $postdata, $headers ) ) || ! $response['code'] ) { // $this->last_error = 'COULDNT_CONNECT'; return false; } return rplg_json_decode( $response['data'] ); } function rplg_urlopen( $url, $postdata = false, $headers = array() ) { $response = array( 'data' => '', 'code' => 0, ); $url = preg_replace( '/\s+/', '+', $url ); if ( function_exists( 'curl_init' ) ) { if ( ! function_exists( 'curl_setopt_array' ) ) { function curl_setopt_array( &$ch, $curl_options ) { foreach ( $curl_options as $option => $value ) { if ( ! curl_setopt( $ch, $option, $value ) ) { return false; } } return true; } } _rplg_curl_urlopen( $url, $postdata, $headers, $response ); } elseif ( ini_get( 'allow_url_fopen' ) && function_exists( 'stream_get_contents' ) ) { _rplg_fopen_urlopen( $url, $postdata, $headers, $response ); } else { _rplg_fsockopen_urlopen( $url, $postdata, $headers, $response ); } return $response; } /*-------------------------------- curl --------------------------------*/ function _rplg_curl_urlopen( $url, $postdata, $headers, &$response ) { $c = curl_init( $url ); if ( ! $c ) { return false; // Handle the error if curl_init fails } $postdata_str = rplg_get_query_string( $postdata ); $c_options = array( CURLOPT_USERAGENT => RPLG_USER_AGENT, CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => ( $postdata_str ? 1 : 0 ), CURLOPT_HEADER => true, CURLOPT_HTTPHEADER => array_merge( array( 'Expect:' ), $headers ), CURLOPT_TIMEOUT => RPLG_SOCKET_TIMEOUT, ); if ( $postdata ) { $c_options[ CURLOPT_POSTFIELDS ] = $postdata_str; } curl_setopt_array( $c, $c_options ); $open_basedir = ini_get( 'open_basedir' ); if ( empty( $open_basedir ) ) { curl_setopt( $c, CURLOPT_FOLLOWLOCATION, true ); } curl_setopt( $c, CURLOPT_SSL_VERIFYPEER, false ); $data = curl_exec( $c ); if ( $data === false ) { curl_close( $c ); return false; // Handle the error if curl_exec fails } // cURL automatically handles Proxy rewrites, remove the "HTTP/1.0 200 Connection established" string if ( stripos( $data, "HTTP/1.0 200 Connection established\r\n\r\n" ) !== false ) { $data = str_ireplace( "HTTP/1.0 200 Connection established\r\n\r\n", '', $data ); } $parts = explode( "\r\n\r\n", $data, 2 ); if ( ! isset( $parts[0] ) || empty( $parts[0] ) ) { curl_close( $c ); return false; } $resp_headers = $parts[0]; $response['data'] = $parts[1]; $response['headers'] = _rplg_get_response_headers( $resp_headers, $response ); $response['code'] = curl_getinfo( $c, CURLINFO_HTTP_CODE ); curl_close( $c ); return $response; } /*-------------------------------- fopen --------------------------------*/ function _rplg_fopen_urlopen( $url, $postdata, $headers, &$response ) { $params = array(); if ( $postdata ) { $params = array( 'http' => array( 'method' => 'POST', 'header' => implode( "\r\n", array_merge( array( 'Content-Type: application/x-www-form-urlencoded' ), $headers ) ), 'content' => rplg_get_query_string( $postdata ), 'timeout' => RPLG_SOCKET_TIMEOUT, ), ); } else { $params = array( 'http' => array( 'header' => implode( "\r\n", $headers ), ), ); } ini_set( 'user_agent', RPLG_USER_AGENT ); $ctx = stream_context_create( $params ); $fp = fopen( $url, 'rb', false, $ctx ); if ( ! $fp ) { return false; } $response_header_array = explode( ' ', $http_response_header[0], 3 ); $unused = $response_header_array[0]; $response['code'] = $response_header_array[0]; $unused = $response_header_array[2]; $resp_headers = array_slice( $http_response_header, 1 ); foreach ( $resp_headers as $unused => $header ) { $header = explode( ':', $header ); $header[0] = trim( $header[0] ); $header[1] = trim( $header[1] ); $resp_headers[ strtolower( $header[0] ) ] = strtolower( $header[1] ); } $response['data'] = stream_get_contents( $fp ); $response['headers'] = $resp_headers; } /*-------------------------------- fsockpen --------------------------------*/ function _rplg_fsockopen_urlopen( $url, $postdata, $headers, &$response ) { $buf = ''; $req = ''; $length = 0; $postdata_str = rplg_get_query_string( $postdata ); $url_pieces = parse_url( $url ); if ( ! isset( $url_pieces['host'] ) ) { return false; // Return false if the URL is invalid } $host = $url_pieces['host']; if ( ! isset( $url_pieces['port'] ) ) { switch ( $url_pieces['scheme'] ) { case 'http': $url_pieces['port'] = 80; break; case 'https': $url_pieces['port'] = 443; $host = 'ssl://' . $url_pieces['host']; break; default: return false; // Return false if the scheme is unsupported } } $url_pieces['path'] = $url_pieces['path'] ?? '/'; $req_host = ( $url_pieces['port'] == 80 && $url_pieces['scheme'] == 'http' ) || ( $url_pieces['port'] == 443 && $url_pieces['scheme'] == 'https' ) ? $url_pieces['host'] : $url_pieces['host'] . ':' . $url_pieces['port']; $fp = @fsockopen( $host, $url_pieces['port'], $errno, $errstr, RPLG_SOCKET_TIMEOUT ); if ( ! $fp ) { return false; // Handle error if fsockopen fails } $path = $url_pieces['path'] . ( isset( $url_pieces['query'] ) ? '?' . $url_pieces['query'] : '' ); $req .= ( $postdata_str ? 'POST' : 'GET' ) . " $path HTTP/1.1\r\n"; $req .= "Host: $req_host\r\n"; $req .= rplg_get_http_headers_for_request( $postdata_str, $headers ); if ( $postdata_str ) { $req .= "\r\n\r\n" . $postdata_str; } $req .= "\r\n\r\n"; fwrite( $fp, $req ); while ( ! feof( $fp ) ) { $buf .= fgets( $fp, 4096 ); } fclose( $fp ); // Close the connection after reading $parts = explode( "\r\n\r\n", $buf, 2 ); if ( ! isset( $parts[1] ) ) { return false; // Handle case where response body is missing } $headers = _rplg_get_response_headers( $parts[0], $response ); $response['data'] = $parts[1]; if ( isset( $headers['transfer-encoding'] ) && strtolower( $headers['transfer-encoding'] ) === 'chunked' ) { $chunk_data = $response['data']; $joined_data = ''; while ( true ) { list( $chunk_length, $chunk_data ) = explode( "\r\n", $chunk_data, 2 ); $chunk_length = hexdec( $chunk_length ); if ( ! $chunk_length || ! strlen( $chunk_data ) ) { break; } $joined_data .= substr( $chunk_data, 0, $chunk_length ); $chunk_data = substr( $chunk_data, $chunk_length + 2 ); // Add 2 for \r\n after chunk $length += $chunk_length; } $response['data'] = $joined_data; } else { $length = $headers['content-length'] ?? strlen( $response['data'] ); } $response['headers'] = $headers; return true; // Return true to indicate success } /*-------------------------------- helpers --------------------------------*/ function rplg_get_query_string( $params ) { $query = ''; if ( $params ) { foreach ( $params as $key => $value ) { $query .= urlencode( $key ) . '=' . urlencode( $value ) . '&'; } } return $query; } function _rplg_get_response_headers( $headers, &$response ) { $headers = explode( "\r\n", $headers ); $header_array = explode( ' ', $headers[0], 3 ); $unused = $header_array[0]; $response['code'] = $header_array[1]; $unused = $header_array[2]; $headers = array_slice( $headers, 1 ); foreach ( $headers as $unused => $header ) { $header = explode( ':', $header ); $header[0] = trim( $header[0] ); $header[1] = trim( $header[1] ); $headers[ strtolower( $header[0] ) ] = $header[1]; } return $headers; } function rplg_get_http_headers_for_request( $content, $headers ) { $req_headers = array(); $req_headers[] = 'User-Agent: ' . RPLG_USER_AGENT; $req_headers[] = 'Connection: close'; if ( $content ) { $req_headers[] = 'Content-Length: ' . strlen( $content ); $req_headers[] = 'Content-Type: application/x-www-form-urlencoded'; } return implode( "\r\n", array_merge( $req_headers, $headers ) ); } function rplg_url_method() { if ( function_exists( 'curl_init' ) ) { return 'curl'; } elseif ( ini_get( 'allow_url_fopen' ) && function_exists( 'stream_get_contents' ) ) { return 'fopen'; } else { return 'fsockopen'; } } }